import Axios from "axios"
import HttpDigestClient from "digest-auth-request"

const baseUrl = "http://192.168.1.13:8000/api/v1"

export default {
    /**
     * 
     * @param {String} userName 
     * @param {String} password 
     */
    signIn(userName, password){
        return new Promise((resolve, rejects) => {
            const request = new HttpDigestClient("POST", `${baseUrl}/Account/SignIn`, userName, password)
            request.loggingOn = false;
            request.request(
                data => {
                    resolve(data)
                },
                errorCode => {
                    rejects(errorCode)
                },
                {

                }
            )
        })
    },
    signUp(name, signInName, signInPassword){
        return Axios.request({
            url: `${baseUrl}/Account`,
            params: {
                name,
                signInName,
                signInPassword
            },
            method: "PUT",
        })
    },
    /**
     * 
     * @param {String} keyWord 
     * @param {"StartsWith|Contains|EndsWith"} searchMode 
     * @param {String} from 
     * @param {Number} pageIndex 
     * @param {Number} count 
     */
    search(keyWord, searchMode, from, pageIndex, count){
        return Axios.request({
            method: "GET",
            params: {
                keyWord,
                searchMode,
                from,
                count,
                pageIndex
            },
            url: `${baseUrl}/Search`
        })
    },
    listDirections(){
        return Axios.request({
            method: "GET",
            url: `${baseUrl}/`
        })
    }
}

